#print "Hello, world."
#print "Hi"
#print "im the dude man"
#print "easy man I have a beverage here"
#print "update"
def initBoard(s):
    a0="_"
    a1="_"
    a2="_"
    a3="_"
    a4="_"
    a5="_"
    a6="_"
    a7="_"
    a8="_"
    print "a0","a1","a2"
    print "a3","a4","a5"
    print "a6","a7","a8"
    w=0
    p1=5
    p2=0
    while check(a0,a1,a2,a3,a4,a5,a6,a7,a8) is not "true" or check2(a0,a1,a2,a3,a4,a5,a6,a7,a8) is not "true":
            
       # while a0=="_" or a1=="_" or a2=="_" or a3=="_" or a4=="_" or a5=="_" or a6=="_" or a7=="_" or a8=="_":
            a=raw_input("enter a space dude 1: ")
            
            if a not in s:
                if a=="a0":
                    a0="x"
                    s.add("a0")
                if a=="a1":
                    a1="x"
                    s.add("a1")
                if a=="a2":
                    a2="x"
                    s.add("a2")
                if a=="a3":
                    a3="x"
                    s.add("a3")
                if a=="a4":
                    a4="x"
                    s.add("a4")
                if a=="a5":
                    a5="x"
                    s.add("a5")
                if a=="a6":
                    a6="x"
                    s.add("a6")
                if a=="a7":
                    a7="x"
                    s.add("a7")
                if a=="a8":
                    a8="x"
                    s.add("a8")
                
                
                print a0,a1,a2
                print a3,a4,a5
                print a6,a7,a8
                
            else:
                print "Already Taken Man! Whats your deal bro?"
                print a0,a1,a2
                print a3,a4,a5
                print a6,a7,a8
            if check(a0,a1,a2,a3,a4,a5,a6,a7,a8)=="true":
                print "The Dude 1 Wins!"
                newGame()
            else:
                
                if check(a0,a1,a2,a3,a4,a5,a6,a7,a8) is not "true":
                    a=raw_input("enter a space dude 2: ")
                
                    if a not in s:
                        if a=="a0":
                            a0="O"
                            s.add("a0")
                        if a=="a1":
                            a1="O"
                            s.add("a1")
                        if a=="a2":
                            a2="O"
                            s.add("a2")
                        if a=="a3":
                            a3="O"
                            s.add("a3")
                        if a=="a4":
                            a4="O"
                            s.add("a4")
                        if a=="a5":
                            a5="O"
                            s.add("a5")
                        if a=="a6":
                            a6="O"
                            s.add("a6")
                        if a=="a7":
                            a7="O"
                            s.add("a7")
                        if a=="a8":
                            a8="O"
                            s.add("a8")
                        
                        print a0,a1,a2
                        print a3,a4,a5
                        print a6,a7,a8
                    else:
                        print "Already Taken Man! Whats your deal bro?"
                        print a0,a1,a2
                        print a3,a4,a5
                        print a6,a7,a8
                if check2(a0,a1,a2,a3,a4,a5,a6,a7,a8)=="true":
                    print "The Dude 2 Wins!"
                    newGame()
                    
        
def check(a0,a1,a2,a3,a4,a5,a6,a7,a8):
    if a0=="x" and a1=="x" and a2=="x":
        return "true"
    if a3=="x" and a4=="x" and a5=="x":
       return "true"
    if a6=="x" and a7=="x" and a7=="x":
        return "true"
    if a0=="x" and a3=="x" and a6=="x":
        return "true"
    if a1=="x" and a4=="x" and a7=="x":
        return "true"
    if a2=="x" and a5=="x" and a8=="x":
        return "true"
    if a0=="x" and a4=="x" and a8=="x":
        return "true"
    if a2=="x" and a4=="x" and a6=="x":
        return "true"
def check2(a0,a1,a2,a3,a4,a5,a6,a7,a8):
    if a0=="O" and a1=="O" and a2=="O":
        return "true"
    if a3=="O" and a4=="O" and a5=="O":
        return "true"
    if a6=="O" and a7=="O" and a8=="O":
        return "true"
    if a0=="O" and a3=="O" and a6=="O":
        return "true"
    if a1=="O" and a4=="O" and a7=="O":
        return "true"
    if a2=="O" and a5=="O" and a8=="O":
        return "true"
    if a0=="O" and a4=="O" and a8=="O":
        return "true"
    if a2=="O" and a4=="O" and a6=="O":
        return "true"
#    if a0=="x" and a1=="x" and a2=="x":
#        return 0
#    if a3=="x" and a4=="x" and a5=="x":
#        return 0
#    if a6=="x" and a7=="x" and a7=="x":
#        return 0
#    if a0=="x" and a3=="x" and a6=="x":
#        return 0
#    if a1=="x" and a4=="x" and a7=="x":
#        return 0
#    if a2=="x" and a5=="x" and a8=="x":
#        return 0
#    if a0=="x" and a4=="x" and a8=="x":
#        return 0
#    if a2=="x" and a4=="x" and a6=="x":
#        return 0
    
#    if a0=="O" and a1=="O" and a2=="O":
#        return 0
#    if a3=="O" and a4=="O" and a5=="O":
#        return 0
#    if a6=="O" and a7=="O" and a7=="O":
#        return 0
#    if a0=="O" and a3=="O" and a6=="O":
#        return 0
#    if a1=="O" and a4=="O" and a7=="O":
#        return 0
#    if a2=="O" and a5=="O" and a8=="O":
#        return 0
#    if a0=="O" and a4=="O" and a8=="O":
#        return 0
#    if a2=="O" and a4=="O" and a6=="O":
#        return 0
    
def newGame():
    x=raw_input("new game? y/n")
    if "y" ==x or "Y" ==x:
        main()
    else:
        print "oh man, later"
    
    
def main():
    print "Welcome to tictacawesome, I'm the dude man"
    print "Lets roll"
    print "enter the space you want ex. a1"
    print "x goes first"
    print "If you pick a space already taken, you lose a turn"
    
    s=set()
    initBoard(s)
    
newGame() 
 
    
    
